package com.itheima.service;

import com.itheima.mapper.ScoreMapper;
import com.itheima.mapper.StaffMapper;
import com.itheima.pojo.Score;
import com.itheima.pojo.Staff;
import com.itheima.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author huangbin
 * @date 2022/6/6 16:13
 */
@Service
public class ScoreService {
    @Autowired
    private ScoreMapper scoreMapper;
    @Autowired
    private StaffMapper staffMapper;
    /**
     * 添加店铺
     *
     * @param score
     * @return
     */
    public Integer add(Score score) {
        return scoreMapper.add(score);
    }

    public List<Score> selectAll() {
        return scoreMapper.selectAll();
    }

    public Score selectById(int id) {
        return scoreMapper.selectById(id);
    }

    public Integer del(int id) {
        //旗舰店无法删除
        if (scoreMapper.selectById(id).getFlagship()==1){
            return -1;}
        List<Staff> staff = staffMapper.selectByScoreId(id);
        System.out.println(staff);
        //查到存在员工，将员工店铺id字段更新问旗舰店字段
        Integer integer = staffMapper.updateScoreIdByid(id);

        // update 员工表 set 员工门店id = 旗舰店id where 员工门店id = 要删除的门店id

        return scoreMapper.del(id);
    }

    public Integer update(Score score) {
        return scoreMapper.update(score);
    }

}
